package pers.leo.couplepointjava.rest;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.leo.couplepointjava.core.response.Result;
import pers.leo.couplepointjava.core.response.ResultController;

import javax.servlet.http.HttpServletRequest;

/**
 * 错误处理页面
 *
 * @author Leo
 * @since 2021/8/26
 */
@RestController
public class Error extends ResultController implements ErrorController {

    @RequestMapping("error")
    public Result handleError(HttpServletRequest request) {
        int statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        String message = (String) request.getAttribute("javax.servlet.error.message");

        return failure(statusCode, message);
    }

}
